package com.whnk.web.controller.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.whnk.common.annotation.Log;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.framework.web.service.ProgramService;
import com.whnk.system.domain.Environment;
import com.whnk.system.domain.Prgm;
import com.whnk.system.service.IEnvironmentService;
import com.whnk.common.base.AjaxResult;

/**
 * 版本环境配置 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-03-26
 */
@Controller
@RequestMapping("/system/environment")
public class EnvironmentController extends BaseController
{
    private String prefix = "system/environment";
	
	@Autowired
	private IEnvironmentService demoService;
	
	@Autowired
	private ProgramService programService;
	
	@RequiresPermissions("system:environment:view")
	@GetMapping()
	public String environment()
	{
	    return prefix + "/demo";
	}
	
	/**
	 * 查询版本环境配置列表
	 */
	@RequiresPermissions("system:environment:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Environment environment)
	{
		startPage();
        List<Environment> list = demoService.selectDemoList(environment);
		return getDataTable(list);
	}
	
	/**
	 * 新增版本环境配置
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 增加异步查询方法查询日期 modify by wxf
	 */
	@ResponseBody
	@GetMapping("/selectD")
	public Map<String,Object> selectProDates(String val) {
		Map<String,Object> rep = new HashMap<>();
		List<Prgm> dList =  programService.getProDate(val);
		rep.put("datas", dList);
		return rep;
	}
	
	/**
	 * 增加异步查询方法查询开发流 modify by wxf
	 */
	@ResponseBody
	@GetMapping("/selectNd")
	public Map<String,Object> selectProNameDates(String val,String nam) {
		Map<String,Object> rep = new HashMap<>();
		List<Prgm> dList =  programService.getNameAndDate(val,nam);
		rep.put("dataL", dList);
		return rep;
	}
	
	/**
	 * 新增保存版本环境配置
	 */
	@RequiresPermissions("system:environment:add")
	@Log(title = "版本环境配置", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Environment environment)
	{		
		return toAjax(demoService.insertDemo(environment));
	}
	
	/**
	 * 复制版本环境配置信息 modify by wxf
	 */
	@GetMapping("/copy/{lgcPk}")
	public String copy(@PathVariable("lgcPk") String lgcPk, ModelMap mmap)
	{
		Environment environment = demoService.selectDemoById(lgcPk);
		mmap.put("environment", environment);
	    return prefix + "/copy";
	}
	
	/**
	 * 复制后保存版本环境配置信息 modify by wxf
	 */
	@RequiresPermissions("system:environment:add")
	@Log(title = "版本环境配置", businessType = BusinessType.INSERT)
	@PostMapping("/copy")
	@ResponseBody
	public AjaxResult copySave(Environment environment)
	{		
		return toAjax(demoService.insertDemo(environment));
	}

	/**
	 * 修改版本环境配置
	 */
	@GetMapping("/edit/{lgcPk}")
	public String edit(@PathVariable("lgcPk") String lgcPk, ModelMap mmap)
	{
		Environment environment = demoService.selectDemoById(lgcPk);
		mmap.put("environment", environment);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存版本环境配置
	 */
	@RequiresPermissions("system:environment:edit")
	@Log(title = "版本环境配置", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Environment environment)
	{		
		return toAjax(demoService.updateDemo(environment));
	}
	
	/**
	 * 删除版本环境配置
	 */
	@RequiresPermissions("system:environment:remove")
	@Log(title = "版本环境配置", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(demoService.deleteDemoByIds(ids));
	}
	
}
